
%!TEX program = xelatex
%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode

\documentclass[10pt]{article} 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 一些常用的包总结在另一个文件里
\input{wang_preamble.tex}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 选择Windows操作系统写中文文档，使用 xelatex 或 lualatex 编译器
%\usepackage{xeCJK} % 处理中文、日文和韩文（统称为 CJK 文字）的排版
%\setCJKmainfont{SimSun} % 设置正文字体为宋体
%\setCJKmonofont{SimHei} % 设置加粗字体为黑体
%\setCJKsansfont{SimHei} % 黑体

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%选择Mac操作系统写中文文档，使用 xelatex 或 lualatex 编译器
\usepackage{xeCJK} % 支持中文字体
\setCJKmainfont{Songti SC} % 设置主要中文字体，用于正文中的中文文本。设置主要中文字体为宋体
%\setCJKmonofont{Menlo} % 设置等宽中文字体，用于代码块、等宽文本等。设置等宽中文字体为 Menlo
%\setCJKsansfont{PingFang SC} % 设置无衬线中文字体，用于标题、图表标签等。设置无衬线中文字体为 PingFang SC
%\setCJKromanfont{Songti SC} % 设置罗马中文字体，用于罗马字体中的中文文本。设置罗马中文字体为宋体

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%选择输出文档的三种类型：
%\newcommand{\showsolution}{0} %%设置showsolution=0, 编译生成试卷
\newcommand{\showsolution}{1} %%设置showsolution=1, 编译生成试卷解答

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 填写课程信息：
\newcommand{\CourseName}{高等代数测验4 - 二次型}
\newcommand{\CourseStudents}{王立庆（2024 级数学与应用数学1班）}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%考完发给学生：

\usepackage{titling}
\setlength{\droptitle}{-2cm}   % 标题上移2cm


\ifnum\showsolution=0
\title{\CourseName }
\author{学号 \underline{\hspace{4cm}} \hspace{1cm} 姓名 \underline{\hspace{4cm}} }
\fi

\ifnum\showsolution=1
\title{\CourseName \,\, 解答 }
\author{\CourseStudents}
\fi

\renewcommand{\today}{\number\year \,年 \number\month \,月 \number\day \,日}
\date{2024年12月19日}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 考完发给学生：给文档加标题、作者、日期、摘要

\maketitle

\thispagestyle{fancy} % 第一页也显示“第几页，共几页”的信息。


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{enumerate}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\newpage 
\item %第1题
设二次型 $f(x_1, x_2,x_3)=2x_1x_2+4x_1x_3+8x_2x_3$.
\begin{enumerate}
\item  写出这个二次型的矩阵。
\item  用配方法将这个二次型化为标准形、实规范形、复规范形，写出使用的线性替换。
\end{enumerate}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 试卷留空位
\ifnum\showsolution=0
\vspace{8cm}
\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%第1题解答
\ifnum\showsolution=1

{\color{red}解答：
\begin{enumerate}[label={\arabic*.}]
\item  将这个二次型写成矩阵乘积的形式，可得
\begin{eqnarray*}
2x_1x_2+4x_1x_3+8x_2x_3 = 
\begin{pmatrix} x_1 & x_2 & x_3 \end{pmatrix}
\begin{pmatrix} 0 & 1 &2  \\ 1 & 0 &4 \\  2& 4 &0  \end{pmatrix}
\begin{pmatrix} x_1 \\ x_2 \\ x_3 \end{pmatrix} = X^tAX. 
\end{eqnarray*}
于是所求的对称矩阵为 
\begin{eqnarray*}
A=\begin{pmatrix} 0 & 1 &2  \\ 1 & 0 &4 \\  2& 4 &0  \end{pmatrix}. 
\end{eqnarray*}

\item  因为没有平方项 $x_1^2$, 所以取变量替换（也可以取其它变量替换） 
\begin{eqnarray*}
\left\{\begin{array}{rcl}
x_1 &=& y_1+y_2, \\ 
x_2 &=& y_1-y_2, \\ 
x_3 &=& y_3,
\end{array}\right.
\hspace{0.5cm} \textrm{即} 
\left\{\begin{array}{rcl}
y_1 &=& \frac{1}{2}x_1+\frac{1}{2}x_2, \\ 
y_2 &=& \frac{1}{2}x_1-\frac{1}{2}x_2, \\ 
y_3 &=& x_3,
\end{array}\right.
\end{eqnarray*}
验证可得系数行列式不等于零，所以这是一个非退化的线性替换。它将二次型化为
\begin{equation*}
\begin{aligned}
2x_1x_2+4x_1x_3+8x_2x_3 
&= 2(y_1+y_2)(y_1-y_2)+4(y_1+y_2)y_3+8(y_1-y_2)y_3 \\ 
&= 2y_1^2 -2y_2^2 +12y_1y_3 -4y_2y_3. 
\end{aligned}
\end{equation*}

\item  进一步使用配方法可得
\begin{equation*}
\begin{aligned}
2y_1^2 -2y_2^2 +12y_1y_3 -4y_2y_3
&= 2(y_1^2+6y_1y_3+9y_3^2) -2y_2^2 -4y_2y_3 - 18y_3^2 \\ 
&= 2(y_1+3y_3)^2 -2(y_2^2 +2y_2y_3 +y_3^2)-16y_3^2 \\ 
&= 2(y_1+3y_3)^2 -2(y_2 +y_3)^2-16y_3^2 \\ 
&=2z_1^2-2z_2^2-16z_3^2,
\end{aligned}
\end{equation*}
这就是题目中的二次型的标准形，即只含有平方项的二次型。最后一步使用的线性替换为
\begin{eqnarray*}
\left\{\begin{array}{rcl}
z_1 &=& y_1+3y_3, \\ 
z_2 &=& y_2+y_3, \\ 
z_3 &=& y_3,  
\end{array}\right.
\end{eqnarray*}
验证系数行列式不等于零，所以这是一个非退化的线性替换。

\item  在标准形的基础上，可得实规范形为
\begin{equation*}
\begin{aligned}
2z_1^2-2z_2^2-16z_3^2 
=w_1^2-w_2^2-w_3^2, 
\end{aligned}
\end{equation*}
其中使用的非退化的线性替换为
\begin{eqnarray*}
\left\{\begin{array}{rcl}
w_1 &=& \sqrt{2}z_1, \\ 
w_2 &=& \sqrt{2}z_2, \\ 
w_3 &=& \sqrt{16}z_3. 
\end{array}\right.
\end{eqnarray*}

\item  在实规范形的基础上，可得复规范形为 
\begin{equation*}
\begin{aligned}
w_1^2-w_2^2-w_3^2
= u_1^2+u_2^2+u_3^2,
\end{aligned}
\end{equation*}
其中使用的非退化的线性替换为
\begin{eqnarray*}
\left\{\begin{array}{rcl}
u_1 &=& w_1, \\ 
u_2 &=& i w_2, \\ 
u_3 &=& i w_3. 
\end{array}\right.
\end{eqnarray*}

\item  使用R语言写出每次变量替换使用的矩阵，并验证得到的二次型：
\begin{lstlisting}[language=R]
library(pracma)A=matrix(c(0,1,2,1,0,4,2,4,0),nrow=3,byrow=T) #输入关于变量X的二次型的系数print(A)C1=matrix(c(1,1,0,1,-1,0,0,0,1),nrow=3,byrow=T) #X=C1YB1=t(C1)%*%A%*%C1 #得到关于变量Y的二次型的系数print(B1)C2=matrix(c(1,0,3,0,1,1,0,0,1),nrow=3,byrow=T) #Z=C2YC2inv=solve(C2) #求逆矩阵B2=t(C2inv)%*%B1%*%C2inv #得到关于变量Z的二次型的系数print(B2)C3=matrix(c(sqrt(2),0,0,0,sqrt(2),0,0,0,sqrt(16)),nrow=3,byrow=T) #W=C3ZC3inv=solve(C3) #求逆矩阵B3=t(C3inv)%*%B2%*%C3inv #得到关于变量W的二次型的系数print(B3)C4=matrix(c(1,0,0,0,1i,0,0,0,1i),nrow=3,byrow=T) #U=C4WC4inv=solve(C4) #求逆矩阵B4=t(C4inv)%*%B3%*%C4inv #得到关于变量U的二次型的系数print(B4)

C=C1%*%C2inv%*%C3inv%*%C4inv #X=CUprint(C)B=t(C)%*%A%*%Cprint(B) #同样得到关于变量U的二次型的系数
\end{lstlisting}

\item  通过上述计算可知，从变量 $X$ 到变量 $U$ 的线性替换为
\begin{eqnarray*}
\begin{pmatrix} x_1 \\ x_2 \\ x_3  \end{pmatrix}
=
\begin{pmatrix} \frac{\sqrt{2}}{2} & -\frac{\sqrt{2}}{2}i &i  \\ \frac{\sqrt{2}}{2} & \frac{\sqrt{2}}{2}i &\frac{1}{2}i \\  0& 0 & -\frac{1}{4}i  \end{pmatrix} 
\begin{pmatrix} u_1  \\ u_2 \\  u_3  \end{pmatrix}. 
\end{eqnarray*}

\end{enumerate}
}

\vspace{0.2cm}

\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\newpage 
\item %第2题
设对称矩阵 
\begin{eqnarray*}
A=\begin{pmatrix} 0 & 1 &2  \\ 1 & 0 &4 \\  2& 4 &0  \end{pmatrix}, 
\end{eqnarray*}
使用初等变换的方法，求可逆矩阵 $C$, 使得 $C^tAC=B$ 成为对角矩阵。

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 试卷留空位
\ifnum\showsolution=0
\vspace{5cm}
\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%第2题解答
\ifnum\showsolution=1

{\color{red}解答：
\begin{enumerate}[label={\arabic*.}]
\item  因为 $(1,1)$ 位置为零，所以将第二行加到第一行，将第二列加到第一列，可得
\begin{eqnarray*}
A \to \begin{pmatrix} 1 & 1 &6  \\ 1 & 0 &4 \\  2& 4 &0  \end{pmatrix}
 \to \begin{pmatrix} 2 & 1 &6  \\ 1 & 0 &4 \\  6& 4 &0  \end{pmatrix} =:D. 
\end{eqnarray*}

\item  用 $(1,1)$ 位置的元素消去下方的元素和右方的元素，可得
\begin{eqnarray*}
D\to \begin{pmatrix} 2 & 1 &6  \\ 0 & -\frac{1}{2} &1 \\  0& 1 &-18  \end{pmatrix} 
\to \begin{pmatrix} 2 & 0 &0  \\ 0 & -\frac{1}{2} &1 \\  0& 1 &-18  \end{pmatrix} =:H. 
\end{eqnarray*}

\item  用 $(2,2)$ 位置的元素消去下方的元素和右方的元素，可得
\begin{eqnarray*}
H\to \begin{pmatrix} 2 & 0 &0  \\ 0 & -\frac{1}{2} &1 \\  0& 0 &-16  \end{pmatrix} 
\to \begin{pmatrix} 2 & 0 &0  \\ 0 & -\frac{1}{2} &0 \\  0& 0 &-16  \end{pmatrix} =:B. 
\end{eqnarray*}

\item  将所有使用的列变换按照先后次序乘起来，可得所求的可逆矩阵为 
\begin{eqnarray*}
C=\begin{pmatrix} 1 & 0 &0  \\ 1 & 1 &0 \\  0& 0 &1  \end{pmatrix} 
\begin{pmatrix} 1 & -\frac{1}{2} &0  \\ 0 & 1 &0 \\  0& 0 &1  \end{pmatrix} 
\begin{pmatrix} 1 & 0 &-3  \\ 0 & 1 &0 \\  0& 0 &1  \end{pmatrix} 
\begin{pmatrix} 1 & 0 &0  \\ 0 & 1 &2 \\  0& 0 &1  \end{pmatrix} 
=
\begin{pmatrix} 1 & -\frac{1}{2} &-4  \\ 1 & \frac{1}{2} &-2 \\  0& 0 &1  \end{pmatrix}. 
\end{eqnarray*}

\item  使用R语言计算矩阵 $C$ 以及验证 $C^tAC$ 等于矩阵 $B$ :
\begin{lstlisting}[language=R]
library(pracma)Q1=matrix(c(1,0,0,1,1,0,0,0,1),nrow=3,byrow=T) #第1次初等列变换Q2=matrix(c(1,-1/2,0,0,1,0,0,0,1),nrow=3,byrow=T) #第2次初等列变换Q3=matrix(c(1,0,-3,0,1,0,0,0,1),nrow=3,byrow=T) #第3次初等列变换Q4=matrix(c(1,0,0,0,1,2,0,0,1),nrow=3,byrow=T) #第4次初等列变换C=Q1%*%Q2%*%Q3%*%Q4 #将四个初等矩阵乘起来print(C)A=matrix(c(0,1,2,1,0,4,2,4,0),nrow=3,byrow=T)B=t(C)%*%A%*%C #验证合同变换的结果print(B)
\end{lstlisting}

\end{enumerate}
}

\vspace{0.2cm}

\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newpage 
\item %第3题
设实二次型 $f(x_1, x_2, x_3)=x_1^2+2x_2^2+x_3^2+2x_1x_2+6x_1x_3+8x_2x_3$. 
\begin{enumerate}
\item  使用配方法，将 $f$ 化为实二次型的标准型，写出使用的变量替换。
\item  求实二次型 $f$ 的秩与符号差，判断 $f$ 是否为正定二次型。
\item  求实对称阵 $A$ 使得 $f(x_1,x_2,x_3)=X^tAX$. 
\item  计算矩阵 $A$ 的顺序主子式，判断 $A$ 是否为正定矩阵。
\end{enumerate}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 试卷留空位
\ifnum\showsolution=0
\vspace{5cm}
\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%第3题解答
\ifnum\showsolution=1

{\color{red}解答：
\begin{enumerate}[label={\arabic*.}]
\item  先将与 $x_1$ 有关的项配成完全平方，然后在剩下的项中，将与 $x_2$ 有关的项配成完全平方，可得
\begin{eqnarray*}
f(x_1, x_2, x_3) &=& x_1^2+2x_2^2+x_3^2+2x_1x_2+6x_1x_3+8x_2x_3 \\ 
&=& (x_1+x_2+3x_3)^2 + x_2^2+2x_2x_3 - 8x_3^2 \\
&=& (x_1+x_2+3x_3)^2 + (x_2+x_3)^2 - 9x_3^2 \\ 
&=& y_1^2+y_2^2-y_3^2. 
\end{eqnarray*}
使用的变量替换为
\begin{eqnarray*}
\left\{\begin{array}{rcl}
y_1 &=&  x_1+x_2+3x_3 \\ 
y_2 &=& x_2+x_3 \\ 
y_3 &=& 3x_3.
\end{array}\right.
\end{eqnarray*}

\item  因为实二次型 $y_1^2+y_2^2-y_3^2$ 的正惯性指数 $p=2$, 负惯性指数 $q=1$, 所以秩 $r=p+q=3$, 符号差 $s=p-q=1$. 这个实二次型不是正定的。

\item  将这个二次型写成矩阵乘积的形式，可得
\begin{eqnarray*}
x_1^2+2x_2^2+x_3^2+2x_1x_2+6x_1x_3+8x_2x_3 = 
\begin{pmatrix} x_1 & x_2 & x_3 \end{pmatrix}
\begin{pmatrix} 1 & 1 &3  \\ 1 & 2 &4 \\  3& 4 &1  \end{pmatrix}
\begin{pmatrix} x_1 \\ x_2 \\ x_3 \end{pmatrix}. 
\end{eqnarray*}
于是所求的对称矩阵为 
\begin{eqnarray*}
A=\begin{pmatrix} 1 & 1 &3  \\ 1 & 2 &4 \\  3& 4 &1  \end{pmatrix}. 
\end{eqnarray*}

\item  矩阵 $A$ 的顺序主子式为
\begin{eqnarray*}
A_1 = 1, \hspace{0.3cm} 
A_2 = \begin{vmatrix} 1 & 1  \\ 1 & 2  \end{vmatrix}=1,  \hspace{0.3cm} 
A_3 = \begin{vmatrix} 1 & 1 &3  \\ 1 & 2 &4 \\  3& 4 &1  \end{vmatrix} = -9. 
\end{eqnarray*}
因为矩阵 $A$ 的顺序主子式不是都大于零，所以 $A$ 不是正定矩阵。


\end{enumerate}
}

\vspace{0.2cm}

\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{enumerate}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%试卷结束
\end{document}


